import gameEnvironment.Environment;
import gameInventory.Inventory;
import gameMap.Map;
import gameMap.Map2;
import gameMiniGames.CircuitButton;
import gameMiniGames.ConnectFour;
import gameMiniGames.Unscramble;
import gameSprites.PChar;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;

import javax.imageio.*;
import javax.swing.*;
/**
 * @author Logical Solutions
 *
 */

public class ActiveScreen implements MouseListener, KeyListener {

	int width = 640;//640
	int height = 480;//480	
		
	JFrame frame = null;
	JLayeredPane currentPane;
	//JLayeredPane mapPane1;
	//JLayeredPane mapPanel2;
	JLayeredPane invPane;
	//JLayeredPane gamePane;
	
	Unscramble uns = new Unscramble();
	CircuitButton cb = new CircuitButton();
	//ConnectFour c4 = new ConnectFour();
	
	int roomValue = 0;
	
	long runningTime = 0;
	boolean running = false;
	
	Environment mansion = new Environment();
	PChar mainChar = new PChar();
	//Map map = new Map();
	Map2 map2 = new Map2();
	Map map = new Map();
	Inventory inv = new Inventory();
		
	//ROOM
	//ImageIcon roomIcon = new ImageIcon("src/roomImages/basement.jpg");
	ImageIcon roomIcon = mansion.getRoom(roomValue);
	//Image roomImage = roomIcon.getImage();
	//BufferedImage room = new BufferedImage(640,480,BufferedImage.TYPE_INT_ARGB);
	JLabel roomLabel = new JLabel(roomIcon);
	
	//HOT SPOT
	//BufferedImage[] hs = new BufferedImage[mansion.totalRooms()];// = mansion.getHSFile(roomValue);
	BufferedImage hs = null;
	//ImageIcon hsIcon = mansion.getHSRoom(roomValue);
	//ImageIcon hsIcon = new ImageIcon("src/hotspotImages/basementHotspot.png");
	//Image hsImage = hsIcon.getImage();	
	//BufferedImage hs = new BufferedImage(640,480,BufferedImage.TYPE_INT_ARGB);	
	//JLabel HSLabel = new JLabel(hsIcon);
	
	//MAIN CHAR
	ImageIcon mainCharIcon = mainChar.getSpriteDown(0);
	JLabel pChar = new JLabel(mainCharIcon);
	//JLabel pChar = new JLabel(new ImageIcon("src/spriteImages/down1.png"));
	
	//MAP
	//ImageIcon mapIcon = map.showMap();
	//JLabel mapLabel = map.mapLabel;	
	
	//INVENTORY
	//JLabel invLabel = new JLabel(inv.icon);
	//	new ImageIcon("src/inventory.png")
	
	//NPC - DAVE SMALL
	JLabel daveLabel = new JLabel(new ImageIcon("src/npcImages/daveDown.png"));
	
	//NPC - MIKE
	JLabel sLabel = new JLabel(new ImageIcon("src/npcImages/mikeRight.png"));
	
	//BIKE
	ImageIcon bike1 = new ImageIcon("src/objectImages/bike1.png");
	ImageIcon bike2 = new ImageIcon("src/objectImages/bike2.png");
	ImageIcon bike3 = new ImageIcon("src/objectImages/bike3.png");
	ImageIcon bike4 = new ImageIcon("src/objectImages/bike4.png");
	ImageIcon bike5 = new ImageIcon("src/objectImages/bikeFinish.png");
	JLabel bike = new JLabel(bike1);
	
	
	JPanel panel = new JPanel(new CardLayout());
	boolean invToggle=false, mapToggle=false, firstTime = true, messageOne = true, messageTwo = true;
	
	String[] url = { 	new String("src/hotspotImages/foyerHotspot.png"),
			new String("src/hotspotImages/basementHotspot.png"),
			new String("src/hotspotImages/GreatRoomHS.png"),
			new String("src/hotspotImages/officeHS.png"),
			new String("src/hotspotImages/GuestRoomHS.png"),
			new String("src/hotspotImages/BathroomHS.png"),
			new String("src/hotspotImages/MapRoomHS.png"),
			new String("src/hotspotImages/DiningRoomHS.png"),
			new String("src/hotspotImages/KitchenHS.png"),
			new String("src/hotspotImages/poolHS.png"),
			new String("src/hotspotImages/tigerHS.png"),
			new String("src/hotspotImages/MasterBedroomHS.png"),
			new String("src/hotspotImages/HallHS.png"),
			new String("src/hotspotImages/EntertainHS.png"),
			new String("src/hotspotImages/PatioHS.png"),
			new String("src/hotspotImages/HedgeMazeHS.png"),
			new String("src/hotspotImages/GuestRoom2HS.png"),
			new String("src/hotspotImages/Bathroom2HS.png"),
			new String("src/hotspotImages/GreatRoomTopHS.png")};
	
	public ActiveScreen(JFrame mainFrame) 
	{		
		frame = mainFrame;
		Dimension screenSize =  Toolkit.getDefaultToolkit().getScreenSize();
		frame.setBounds(screenSize.width/2-(width/2),screenSize.height/2-(height/2),width,height);
		frame.setVisible(true);
		frame.addWindowListener( new WindowAdapter() 
		{
			public void windowClosing(WindowEvent e)
			{
				System.exit(0);
			}
		});
		frame.setResizable(false);		
		
		frame.addKeyListener(this);
		
		frame.addWindowFocusListener(new WindowFocusListener() {
			public void windowGainedFocus(WindowEvent arg0) {
				
			}
			public void windowLostFocus(WindowEvent arg0)
			{
				
			}
		});
	}
	
	public void switchScreen(JPanel panel) {
		
	}
	
	public void startGame() {
		running = true;
		while(isRunning())
		{			
			long startTime = System.currentTimeMillis();
			runningTime = System.currentTimeMillis() - startTime;
			
			running = false;
			
			//current pane			
			currentPane = new JLayeredPane();
			currentPane.setOpaque(false);
			currentPane.setLayout(null);
			currentPane.setBounds(0,0,640,480);
			
			//mansion = new Environment(currentPane);
			mansion.playAudio(roomValue);
			
			currentPane.add(pChar, new Integer(5), 0);
			//currentPane.add(daveLabel, new Integer(4), 0);
			currentPane.add(sLabel, new Integer(4), 0);
			currentPane.add(roomLabel, new Integer(3), 0);
			//currentPane.add(mapLabel, new Integer(2), 0);
			//currentPane.add(map.firstButton, new Integer(2),0);
			//currentPane.add(inv.invLabel, new Integer(1), 0);
			//currentPane.add(inv.bikeLabel, new Integer(0),0);
			//currentPane.add(inv.keyLabel, new Integer(0),0);
			//currentPane.add(inv.leverLabel, new Integer(0),0);
			
			
			pChar.setBounds(new Rectangle(width/2 + 50,height/2 - 35,
							mainChar.getWidth("down",0),mainChar.getHeight("down",0)));
			
			daveLabel.setBounds(new Rectangle(250,200,60,60));
			sLabel.setBounds(new Rectangle(220,140,60,60));
			roomLabel.setBounds(new Rectangle(0,0,640,480));
			//mapLabel.setBounds(new Rectangle(0,0,635,455));
			//inv.invLabel.setBounds(new Rectangle(0,0,640,449));

			//mapPane = new JLayeredPane();
			
			//mapPane2 = (JLayeredPane)map2;
			//mapPane.add(mapLabel,new Integer(0),0);
			invPane = (JLayeredPane)inv;
			//gamePane = new JLayeredPane();
			//gamePane = (JLayeredPane)uns;
			//invPane.add(inv.invLabel,new Integer(0),0);
			
			//gamePane = (JLayeredPane)unscramble;
			
			panel.add(currentPane,"env");
			panel.add(map,"map");
			panel.add(map2,"map2");
			panel.add(invPane,"inv");
			panel.add(cb,"game1");
			panel.add(uns,"game2");
			//panel.add(c4,"game3");
			//uns.aud.stopMusic();
			
			//map2.mapFirst.requestFocus();
			//map2.mapSecond.requestFocus();
			//map2.mapFirst.addMouseListener(this);
			//map2.mapSecond.addMouseListener(this);
			
			
			
			
			//frame.add(comboBoxPane, BorderLayout.PAGE_START);
	        frame.add(panel);
	        
//			mainChar=new PChar(currentPane);
			//frame.add(currentPane);
		}
	}	
	
	
	
	
	public void nextRoom(int roomValue)
	{			
		roomLabel.setIcon(mansion.getRoom(roomValue));
		//HSLabel.setIcon(mansion.getHSRoom(roomValue));
		//mansion.playAudio(roomValue); //plays different songs in each room
		//boolean firstTime1 = true;
		//boolean firstTime2 = true;
		//boolean firstTime3 = true;
		//boolean firstTime4 = true;
		if(roomValue != 0)//add boolean ..if talked to
		{
			currentPane.remove(sLabel);
		}
		else if(roomValue == 0)
		{
			currentPane.add(sLabel, new Integer(3), 0);
			sLabel.setBounds(new Rectangle(220,140,60,60));
		}			
		if(roomValue == 3 && inv.firstTime == true)//office
		{
			currentPane.add(bike, new Integer(4), 0);
			bike.setBounds(new Rectangle(width/2,height/2,bike1.getIconWidth(), bike1.getIconHeight()));
			//firstTime = false;
		}
		else if(roomValue == 6 && inv.firstTime1 == true)//map
		{
			currentPane.add(bike, new Integer(4), 0);
			bike.setBounds(new Rectangle(180,200,bike2.getIconWidth(), bike2.getIconHeight()));
			bike.setIcon(bike2);
			//firstTime1 = false;
		}
		else if(roomValue == 8 && inv.firstTime2 == true)//kitchen
		{
			currentPane.add(bike, new Integer(4), 0);
			bike.setBounds(new Rectangle(width/2,height/2,bike3.getIconWidth(), bike3.getIconHeight()));
			bike.setIcon(bike3);
			//firstTime2 = false;
		}
		else if(roomValue == 9 && inv.firstTime3 == true)//pool
		{
			currentPane.add(bike, new Integer(4), 0);
			bike.setBounds(new Rectangle(400,350,bike4.getIconWidth(), bike4.getIconHeight()));
			bike.setIcon(bike4);
			//firstTime3 = false;
		}
		else if(roomValue == 1 && inv.counter >= 4)
		{
			currentPane.add(bike, new Integer(3), 0);
			bike.setBounds(new Rectangle(190,150,bike5.getIconWidth(), bike5.getIconHeight()));
			bike.setIcon(bike5);
		}
		else
		{
			currentPane.remove(bike);
		}

	}
	
	
	
	public int getRoom(int color)
	{	
		int roomColor=-1;
		if(color == -16732432 || color == -16732433)
		{
			roomColor = 0;//foyer
		}
		else if(color == -16776961)//CHANGE
		{
			roomColor = 1;//basement
		}
		else if(color == -9580554)
		{
			roomColor = 2;//greatroom
		}
		else if(color == -16758144)//CHANGE
		{
			roomColor = 3;//office
		}
		else if(color == -16747844)
		{
			roomColor = 4; //guest bedroom
		}	
		else if(color == -16763791)
		{
			roomColor = 5; //bathroom
		}
		else if(color == -15002524)
		{
			roomColor = 6;//maproom
		}
		else if(color == -6191426)
		{
			roomColor = 7;//diningroom
		}
		else if(color == -12317086)
		{
			roomColor = 8;//kitchen
		}
		else if(color == -7198833)
		{
			roomColor = 9;//pool
		}
		else if(color == -1245044)
		{
			roomColor = 10;//secret
		}
		else if(color == -8716218)
		{
			roomColor = 11;//master bedroom
		}
		else if(color == -16755546)
		{
			roomColor = 12;//hallway
		}
		else if(color == -7896642)
		{
			roomColor = 13;//entertainment
		}
		else if(color == -16763293)
		{
			roomColor = 14;//patio
		}		
		else if(color == -16733795)
		{
			roomColor = 15; //hedgemaze
		}
		else if(color == -10462039)
		{
			roomColor = 16;//guest room 2
		}
		else if(color == -6422435)
		{
			roomColor = 17;//tiger room
		}	
		else if (color == -12284725)
		{
			roomColor = 18;//master bedroom top
		}		
		return roomColor;
	}
	
	public void playGame(int roomValue)
	{
		if(roomValue == 1)
		{
			//basement
			CardLayout cl = (CardLayout)(panel.getLayout());			
			cl.show(panel,"game1");
		}
		else if(roomValue == 16)
		{
			CardLayout cl = (CardLayout)(panel.getLayout());			
			cl.show(panel,"game2");
		}
		else if(roomValue == 4)
		{
			CardLayout cl = (CardLayout)(panel.getLayout());			
			cl.show(panel,"game3");
		}
	}

	private class Walker extends Thread {
		private int step, xStep, yStep, index;
		private int ccolor, color, x,y,topY, bottomY, leftX, rightX;
		
		private Walker(int index, int xStep, int yStep) {
			this.step = 0;
			this.index = index;
			this.xStep = xStep;
			this.yStep = yStep;
			
			try {
				hs = ImageIO.read(new File(url[roomValue]));
			} 
			catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			/*if(roomValue == 1)
			{
				Point point = pChar.getLocation();
				point.x += 100;
				point.y += 100;
				
				pChar.setLocation(point);
			}*/
		}
		
		public int checkXCollision(int y, int leftX, int rightX)
		{
			ccolor = -1;
			while(leftX < rightX)
			{
				color = hs.getRGB(leftX,y);
				if(color != -1)
				{
					ccolor = color;
					//System.out.println("collision color: " + ccolor);
				}
				leftX++;
				//break;
			}
			//System.out.println("collision color: " + ccolor);
			return ccolor;
		}
		
		public int checkYCollision(int x, int topY, int bottomY)
		{
			ccolor = -1;
			while(topY <= bottomY)
			{
				color = hs.getRGB(x,topY);
				if(color != -1)
				{
					ccolor = color;
					//System.out.println("collision color: " + ccolor);
				}
				topY++;
				//break;
			}
			//System.out.println("collision color: " + ccolor);
			return ccolor;
		}
		
		public void run() {
			while (step < 4)
			{			
				Point p = pChar.getLocation();	
				Point hsp = pChar.getLocation();
				color = hs.getRGB(p.x,p.y);
				
				if(color == -1)
				{
					p.x += xStep;
					p.y += yStep;
					if(xStep==-8)//top Y to bottom Y
					{
						x = hsp.x + xStep;
						topY = hsp.y;
						bottomY = (hsp.y+mainChar.getHeight("left",index+step));
						//System.out.print("x: " + (hsp.x));
						//System.out.print(" y: " + (topY) + "\n");
						color = checkYCollision(x,topY,bottomY);
						System.out.println("color: " + color);
						pChar.setIcon(mainChar.getSpriteLeft(index+step));
						if(color != -1)
						{
							if(color == -16777216 || color == -16711936 || color == -65536 || color == -746814)
							{
								p.x -= xStep;
								p.y -= yStep;
								if(color == -65536 && cb.beenPlayed() == false && roomValue == 1)
								{
									playGame(roomValue);
									cb.setPlayed(true);
									inv.keyIncrease();
								}
								else if(color == -65536 && uns.beenPlayed() == false && roomValue == 16)
								{
									playGame(roomValue);
									uns.setPlayed(true);
									inv.keyIncrease();
								}								
								else if(color == -65536 && roomValue == 4)
								{
									//playGame(roomValue);
									//c4.setPlayed(true);
								}
								else if(color == -746814 && messageOne == true && roomValue == 0 && cb.played == false)
								{
									JOptionPane.showMessageDialog(null,"Find the breaker to turn on the light.","MIKE: ", JOptionPane.INFORMATION_MESSAGE);
									messageOne = false;
								}
								else if(color == -746814 && cb.played == true && roomValue == 0 && messageTwo == true)
								{
									JOptionPane.showMessageDialog(null,"Hey now can you help me find my bike pieces","MIKE: ", JOptionPane.INFORMATION_MESSAGE);
									messageTwo = false;
								}
							}
							else if(color == -824241 || color == -3584 || color == -1172444 || color == -891614)
							{
								inv.bikeIncrease(color);
								currentPane.remove(bike);
							}
							else {
								System.out.println("color: "+color);
								roomValue = getRoom(color);							
								nextRoom(roomValue);
							}
							p.x += xStep;
							p.y += yStep;
							pChar.setLocation(p);
						}
					}
					else if(xStep==8)//top Y to bottom Y
					{	
						x = hsp.x + mainChar.getWidth("right",index+step); //add image width
						topY = hsp.y;
						bottomY = (hsp.y+mainChar.getHeight("right", index+step));
						System.out.print("x: " + (hsp.x));
						System.out.print(" y: " + (topY) + "\n");
						//color = hs.getRGB(hsp.x,hsp.y);
						color = checkYCollision(x,topY,bottomY);
						System.out.println("color: " + color);
						pChar.setIcon(mainChar.getSpriteRight(index+step));
						if(color != -1)
						{	
							if(color == -16777216 || color == -16711936 || color == -65536 || color == -746814)
							{
								p.x -= xStep;
								p.y -= yStep;
								if(color == -65536 && cb.beenPlayed() == false && roomValue == 1)
								{
									playGame(roomValue);
									cb.setPlayed(true);
									inv.keyIncrease();
								}
								else if(color == -65536 && uns.beenPlayed() == false && roomValue == 16)
								{
									playGame(roomValue);
									uns.setPlayed(true);
									inv.keyIncrease();
								}
								else if(color == -65536 && roomValue == 4)
								{
									//playGame(roomValue);
									//c4.setPlayed(true);
								}
								else if(color == -746814 && messageOne == true && roomValue == 0 && cb.played == false)
								{
									JOptionPane.showMessageDialog(null,"Find the breaker to turn on the light.","MIKE: ", JOptionPane.INFORMATION_MESSAGE);
									messageOne = false;
								}
								else if(color == -746814 && cb.played == true && roomValue == 0 && messageTwo == true)
								{
									JOptionPane.showMessageDialog(null,"Hey now can you help me find my bike pieces","MIKE: ", JOptionPane.INFORMATION_MESSAGE);
									messageTwo = false;
								}
							}
							else if(color == -824241 || color == -3584 || color == -1172444 || color == -891614)
							{
								inv.bikeIncrease(color);
								currentPane.remove(bike);
							}
							else {
								roomValue = getRoom(color);
								nextRoom(roomValue);
							}
							p.x -= xStep;
							p.y -= yStep;
							pChar.setLocation(p);
						}
					}
					else if(yStep==-8)//left X to right X
					{
						y = hsp.y + yStep;
						leftX = hsp.x;
						rightX = (hsp.x+mainChar.getWidth("up", index+step));
						System.out.print("x: " + (hsp.x));
						System.out.print(" y: " + (y) + "\n");
						//color = hs.getRGB(hsp.x,hsp.y);
						color = checkXCollision(y,leftX,rightX);
						System.out.println("color: " + color);
						pChar.setIcon(mainChar.getSpriteUp(index+step));
						if(color != -1)
						{
							if(color == -16777216 || color == -16711936 || color == -65536 || color == -746814)
							{
								p.x -= xStep;
								p.y -= yStep;
								if(color == -65536 && cb.beenPlayed() == false && roomValue == 1)
								{
									playGame(roomValue);
									cb.setPlayed(true);
									inv.keyIncrease();
								}
								else if(color == -65536 && uns.beenPlayed() == false && roomValue == 16)
								{
									playGame(roomValue);
									uns.setPlayed(true);
									inv.keyIncrease();
								}
								else if(color == -65536 && roomValue == 4)
								{
									//playGame(roomValue);
									//c4.setPlayed(true);
								}
								else if(color == -746814 && messageOne == true && roomValue == 0 && cb.played == false)
								{
									JOptionPane.showMessageDialog(null,"Find the breaker to turn on the light.","MIKE: ", JOptionPane.INFORMATION_MESSAGE);
									messageOne = false;
								}
								else if(color == -746814 && cb.played == true && roomValue == 0 && messageTwo == true)
								{
									JOptionPane.showMessageDialog(null,"Hey now can you help me find my bike pieces","MIKE: ", JOptionPane.INFORMATION_MESSAGE);
									messageTwo = false;
								}
							}
							else if(color == -824241 || color == -3584 || color == -1172444 || color == -891614)
							{
								inv.bikeIncrease(color);
								currentPane.remove(bike);
							}
							else {
								roomValue = getRoom(color);						
								nextRoom(roomValue);
							}
							p.x -= xStep;
							p.y -= yStep;
							pChar.setLocation(p);
						}
					}
					else if(yStep==8)//left X to right X
					{
						y = hsp.y + mainChar.getHeight("down",index+step); //add image height
						leftX = hsp.x;
						rightX = (hsp.x+mainChar.getWidth("down", index+step));
						System.out.print("x: " + (hsp.x));
						System.out.print(" y: " + (y) + "\n");
						color = checkXCollision(y,leftX,rightX);
						//color = hs.getRGB(hsp.x,hsp.y);
						System.out.println("color: " + color);
						pChar.setIcon(mainChar.getSpriteDown(index+step));
						if(color != -1)
						{
							if(color == -16777216 || color == -16711936 || color == -65536 || color == -746814)
							{
								p.x -= xStep;
								p.y -= yStep;
								if(color == -65536 && cb.beenPlayed() == false && roomValue == 1)
								{
									playGame(roomValue);
									cb.setPlayed(true);
									inv.keyIncrease();
								}
								else if(color == -65536 && uns.beenPlayed() == false && roomValue == 16)
								{
									playGame(roomValue);
									uns.setPlayed(true);
									inv.keyIncrease();
								}
								else if(color == -65536 && roomValue == 4)
								{
									//playGame(roomValue);
									//c4.setPlayed(true);
								}
								else if(color == -746814 && messageOne == true && roomValue == 0 && cb.played == false)
								{
									JOptionPane.showMessageDialog(null,"Find the breaker to turn on the light.","MIKE: ", JOptionPane.INFORMATION_MESSAGE);
									messageOne = false;
								}
								else if(color == -746814 && cb.played == true && roomValue == 0 && messageTwo == true)
								{
									JOptionPane.showMessageDialog(null,"Hey now can you help me find my bike pieces","MIKE: ", JOptionPane.INFORMATION_MESSAGE);
									messageTwo = false;
								}
							}
							else if(color == -824241 || color == -3584 || color == -1172444 || color == -891614)
							{
								inv.bikeIncrease(color);
								currentPane.remove(bike);
							}
							else {
								roomValue = getRoom(color);
								nextRoom(roomValue);
							}
							p.x -= xStep;
							p.y -= yStep;
							pChar.setLocation(p);						
						}
					}				
					pChar.setLocation(p);
					step++;
					try {
						Thread.sleep(100);
					}
					catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				else if(color != -1)
				{
					p.x -= xStep;
					p.y -= yStep;
					System.out.println("COLLISION!");
					if(xStep==-8)
					{
						pChar.setIcon(mainChar.getSpriteLeft(index+step));
					}
					else if(xStep==8)
					{
						pChar.setIcon(mainChar.getSpriteRight(index+step));
					}
					else if(yStep==-8)
					{
						pChar.setIcon(mainChar.getSpriteUp(index+step));
					}
					else if(yStep==8)
					{
						pChar.setIcon(mainChar.getSpriteDown(index+step));
					}
					pChar.setLocation(p);
					step=4;
				}
			}
		}
	}	
	
	public void endGame()
	{
		
	}
	
	private boolean isRunning() {
		return running;
	}
	
	private long getTime()
	{
		return runningTime;
	}
	
	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub
		int code = e.getKeyCode();
		if(code == KeyEvent.VK_G)
		{
			CardLayout cl = (CardLayout)(panel.getLayout());				
			cl.show(panel,"env");
		}
		if(code == KeyEvent.VK_M)
		{
			System.out.println("You opened the map1!");
			if(mapToggle)
			{
				CardLayout cl = (CardLayout)(panel.getLayout());			
				cl.show(panel,"map");
				mapToggle=false;
			}
			else
			{
				CardLayout cl = (CardLayout)(panel.getLayout());				
				cl.show(panel,"env");
				mapToggle=true;
			}
		}
		if(code == KeyEvent.VK_N)
		{
			System.out.println("You opened the map2!");
			if(mapToggle)
			{
				CardLayout cl = (CardLayout)(panel.getLayout());			
				cl.show(panel,"map2");
				mapToggle=false;
			}
			else
			{
				CardLayout cl = (CardLayout)(panel.getLayout());				
				cl.show(panel,"env");
				mapToggle=true;
			}
		}
		if(code == KeyEvent.VK_I)
		{
			System.out.println("You opened the inventory!");
			if(invToggle)
			{
				CardLayout cl = (CardLayout)(panel.getLayout());			
				cl.show(panel,"inv");
				if(inv.counter >= 4 && firstTime == true)
				{
					JOptionPane.showMessageDialog(null,"Visit the basement.","HINT", JOptionPane.INFORMATION_MESSAGE);
					firstTime = false;
				}				
				invToggle=false;
			}
			else
			{
				CardLayout cl = (CardLayout)(panel.getLayout());				
				cl.show(panel,"env");
				invToggle=true;
			}
		}
		if(code == KeyEvent.VK_DOWN)
		{
			System.out.println("You pressed down!");
			new Walker(0,0,8).start();
		}
		if(code == KeyEvent.VK_UP)
		{
			System.out.println("You pressed up!");
			new Walker(0,0,-8).start();
		}
		if(code == KeyEvent.VK_LEFT)
		{
			System.out.println("You pressed left!");
			new Walker(0,-8,0).start();
		}
		if(code == KeyEvent.VK_RIGHT)
		{
			System.out.println("You pressed right!");
			new Walker(0,8,0).start();
		}
	}

	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub		
	}

	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub		
	}

	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		/*if(e.getComponent() == map2.mapSecond)
		{
			map2.removeAll();
			map2.mapLabel.setIcon(map2.imagesMap2);
			map2.add(map2.mapLabel, new Integer(0));
			map2.add(map2.mapFirst, new Integer(3));
			//panel.requestFocus();
		}
		
		if(e.getComponent() == map2.mapFirst)
		{
			map2.removeAll();
			map2.mapLabel.setIcon(map2.imagesMap);
			map2.add(map2.mapLabel, new Integer(0));
			map2.add(map2.mapSecond, new Integer(3));
			map2.makeGray();
			//panel.requestFocus();
			/*for(int a = 0; a < map2.rV.size(); a++){
				if(map2.rV.get(a) != null){
					map2.add(map2.jM[map2.rV.get(a)], new Integer(4));
				}
			}
		}*/
	}

	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
} 
